﻿using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using WaterCloud.Code;
using WaterCloud.Domain.RecruitmentManagement;
using WaterCloud.Service;
using Microsoft.AspNetCore.Authorization;
using WaterCloud.Service.RecruitmentManagement;
using WaterCloud.Service.SystemOrganize;
using Org.BouncyCastle.Crypto;

namespace WaterCloud.Web.Areas.RecruitmentManagement.Controllers
{
    /// <summary>
    /// 创 建：超级管理员
    /// 日 期：2025-04-03 10:48
    /// 描 述：人才库控制器类
    /// </summary>
    [Area("RecruitmentManagement")]
    public class PersonnelController :  BaseController
    {
        public PersonnelService _service {get;set;}

        #region 获取数据
        [HttpGet]
        public virtual ActionResult Index1()
        {
            return View();
        }
        [HttpGet]
        public virtual ActionResult Index2()
        {
            return View();
        }
        [HttpGet]
        public virtual ActionResult AddForm()
        {
            return View();
        }
        [HandlerAjaxOnly]
        [IgnoreAntiforgeryToken]
        public async Task<ActionResult> GetGridJson(SoulPage<PersonnelEntity> pagination, int zt,string keyword)
        {
            if (string.IsNullOrEmpty(pagination.field))
            {
                pagination.field = "F_Id";
                pagination.order = "desc";
            }
            var data = await _service.GetLookList(pagination,zt,keyword);
          

            return Content(pagination.setData(data).ToJson());
        }



      
        public async Task<ActionResult> GetListJson(string keyword, string ids)
            {
                var data = await _service.GetList(keyword);
                data = data.Where(a => a.F_State==2).ToList();
                if (!string.IsNullOrEmpty(ids))
                {
                    foreach (var item in ids.Split(','))
                    {
                        var temp = data.Find(a => a.F_Id == item);
                        if (temp != null)
                        {
                            temp.LAY_CHECKED = true;
                        }
                    }
                }
                return Success(data.Count, data);
            }
        

        [HttpGet]
        [HandlerAjaxOnly]
        public async Task<ActionResult> GetFormJson(string keyValue)
        {
            var data = await _service.GetLookForm(keyValue);
            return Content(data.ToJson());
        }
        #endregion

        #region 提交数据
        [HttpPost]
        [HandlerAjaxOnly]
        public async Task<ActionResult> SubmitForm(PersonnelEntity entity, string keyValue)
        {
            try
            {
                await _service.SubmitForm(entity, keyValue);
                return await Success("操作成功。", "", keyValue);
            }
            catch (Exception ex)
            {
                return await Error(ex.Message, "", keyValue);
            }
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        public async Task<ActionResult> DeleteForm(string keyValue)
        {
            try
            {
                await _service.DeleteForm(keyValue);
                return await Success("操作成功。", "", keyValue, DbLogType.Delete);
            }
            catch (Exception ex)
            {
                return await Error(ex.Message, "", keyValue, DbLogType.Delete);
            }
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        public async Task<ActionResult> StateForm(string keyValue,int zt)
        {
            try
            {
                await _service.StateForm(keyValue,zt);
                return await Success("操作成功。", "", keyValue, DbLogType.Delete);
            }
            catch (Exception ex)
            {
                return await Error(ex.Message, "", keyValue, DbLogType.Delete);
            }
        }
        #endregion
    }
}
